package edu.uwp.cs.android.scogenerator;

import de.greenrobot.daogenerator.DaoGenerator;
import de.greenrobot.daogenerator.Entity;
import de.greenrobot.daogenerator.Property;
import de.greenrobot.daogenerator.Schema;
import de.greenrobot.daogenerator.ToMany;

/**
 * Generates entities and DAOs for the SCO prototype project.
 * This prototype was developed for the Mobile Device Programming class
 * in the Spring Semester 2012 at the University of Wisconsin Parkside.
 * 
 * Run it as a Java application (not Android).
 * 
 * This file is based on the ExampleDaoGenerator class created by of Markus Junginger.
 * 
 * @author Michael Tiede, Matthias Kleinert, Moritz Duettmann
 * @since May 2012
 */
public class SCOPrototypeDaoGenerator {

    public static void main(String[] args) throws Exception {
        Schema schema = new Schema(3, "edu.uwp.cs.android.sco.entities"); // packagename
        schema.enableKeepSectionsByDefault(); // set flag to be able to edit generated files
        generateSCOEntities(schema);
        new DaoGenerator().generateAll(schema, "output"); // generate files in output directory
    }
    
    private static void generateSCOEntities(Schema schema) {
    	// generate student entity and DAO
    	Entity student = schema.addEntity("Student");
        student.addIdProperty();
        student.addStringProperty("fName").notNull();
        student.addStringProperty("lName").notNull();
        student.addStringProperty("note");
        student.addDateProperty("lastModified").notNull();
        student.addIntProperty("disabilityLevel");

        // generate disabilty entity and DAO
        Entity disability = schema.addEntity("Disability");
        disability.addIdProperty();
        disability.addStringProperty("name").notNull();
        disability.addStringProperty("info");
        disability.addIntProperty("rating");
        disability.addStringProperty("category").notNull();

        // set properties and relations between Student and Disability
        Property studentId = disability.addLongProperty("studentId").notNull().getProperty();
        ToMany studentToDisability = student.addToMany(disability, studentId);
        studentToDisability.setName("disabilities");
        
        // generate course entity and DAO
        Entity course = schema.addEntity("Course");
        course.addIdProperty();
        course.addStringProperty("name").notNull();
        course.addStringProperty("category").notNull();
        course.addStringProperty("semester").notNull();
        course.addIntProperty("year").notNull();
        
        // generate relCourseStudent entity
        Entity relCourseStudent = schema.addEntity("RelationCourseStudent");
        relCourseStudent.addIdProperty(); // for deleting relation over primary key
        
        // relation between Course and Student will be set manually, not generated by the framework
        Property relStudentId = relCourseStudent.addLongProperty("studentId").notNull().getProperty();
        ToMany studentToRelCourseStudent = course.addToMany(relCourseStudent, relStudentId);
        studentToRelCourseStudent.setName("students");      
        Property relCourseId = relCourseStudent.addLongProperty("courseId").notNull().getProperty();
        ToMany courseToRelCourseStudent = student.addToMany(relCourseStudent, relCourseId);
        courseToRelCourseStudent.setName("courses");
    }

}
